'use strict';
import ServerURL from './ServerURL';
import HttpTool from './HttpTool';
import GCPublic from '../Global/GCPublic';

/*
 * HttpTool(URL,参数,是否Loading[1、0、内容],返回是否提示[1、0、-1(失败时提示)、内容、])
 */
export default class ApiService {
    /*
     * 首页
     */
    static GetCarList(now_page) {
        let formData = new FormData();
        formData.append("now_page", now_page);
        formData.append("registered_id",  GCPublic.GCConst.registeredId);
        formData.append("token",  GCPublic.User.token);
        return new Promise(function (resolve, reject) {
            HttpTool.postWithPath(ServerURL.CAR_LIST_API, formData, 0, 0).then((ret) => {
                resolve(ret);
            }).catch((err) => {
                reject(err);
            });
        });
    }

    static GetHomeInfo(date_type) {
        let formData = new FormData();
        formData.append("date_type", date_type);
        formData.append("is_shop", 1);
        formData.append("registered_id",  GCPublic.GCConst.registeredId);
        formData.append("token",  GCPublic.User.token);
        console.log(formData)
        return new Promise(function (resolve, reject) {
            HttpTool.postWithPath(ServerURL.HOME_API, formData, 0, 1).then((ret) => {
                console.log(ret)
                resolve(ret);
            }).catch((err) => {
                reject(err);
            });
        });
    }

    // ------------------------------------------------------
    /* 
     * 统计
     */
    static QueryAnalysis(date_type, is_shop,now_page) {
        let formData = new FormData();
        formData.append("date_type", date_type);
        formData.append("now_page", now_page);
        formData.append("is_shop",is_shop);
        formData.append("token",  GCPublic.User.token);
        formData.append("registered_id", GCPublic.GCConst.registeredId);
        return new Promise(function (resolve, reject) {
            HttpTool.postWithPath(ServerURL.QUERY_ANALYSIS_API, formData, 1, 0).then((ret) => {
                resolve(ret);
            }).catch((err) => {
                reject(err);
            });
        });
    }

    static QueryBusiness(date_type, is_shop,type) {
        let formData = new FormData();
        formData.append("date_type", date_type);
        formData.append("is_shop",is_shop);
        formData.append("type", type);
        formData.append("token",  GCPublic.User.token);
        formData.append("registered_id", GCPublic.GCConst.registeredId);
        return new Promise(function (resolve, reject) {
            HttpTool.postWithPath(ServerURL.QUERY_BUS_API, formData, 1, 0).then((ret) => {
                resolve(ret);
            }).catch((err) => {
                reject(err);
            });
        });
    }

    // ------------------------------------------------------
    /*
     * 用户中心
     */
    static AboutUs() {
        let formData = new FormData();
        return new Promise(function (resolve, reject) {
            HttpTool.postWithPath(ServerURL.ABOUT_US_API, null, 1, 1).then((ret) => {
                resolve(ret);
            }).catch((err) => {
                reject(err);
            });
        });
    }

    static Login(user_name, password, identity) {
        let formData = new FormData();
        formData.append("mobile", user_name);
        formData.append("password", password);
        formData.append("identity", identity);
        formData.append("registered_id", GCPublic.GCConst.registeredId);
        return new Promise(function (resolve, reject) {
            HttpTool.postWithPath(ServerURL.LOGIN_API, formData, 1, 1).then((ret) => {
                console.log('login',ret)
                resolve(ret);
            }).catch((err) => {
                reject(err);
            });
        });
    }

    static GetMessageList(identity,now_page) {
        let formData = new FormData();
        formData.append("identity", identity);
        formData.append("now_page", now_page);
        formData.append("token",  GCPublic.User.token);
        formData.append("registered_id", GCPublic.GCConst.registeredId);
        return new Promise(function (resolve, reject) {
            HttpTool.postWithPath(ServerURL.MSG_LIST_API, formData, 1, 0).then((ret) => {
                resolve(ret);
            }).catch((err) => {
                reject(err);
            });
        });
    }

}